import 'package:flutter/material.dart';

import '../../utils/ColorUtil.dart';

class CommonWidget{
  /**
   * 顶部标题样式
   */
  PreferredSizeWidget appBar({required Widget title, Widget ? leading,List<Widget>?  actions, PreferredSizeWidget ? bottom}) {
    return AppBar(
      elevation: 1,
      centerTitle: true,
      titleSpacing: 0,
      leading: leading,
      backgroundColor: const Color.fromRGBO(244, 243, 248, 1),
      // 返回按钮
      title: title,
      titleTextStyle: TextStyle(fontSize: 15,color: Colors.black),
      // 标题
      actions: actions,
      bottom: bottom,
    );
  }

  /**
   * 常用标题
   */
  titleBox({required String title, String moreTitle="更多", bool showMore=false,GestureTapCallback? onTap, String ? badge}){
    return GestureDetector(
      onTap: onTap,
      behavior: HitTestBehavior.translucent,
      child: Container(
        margin:  const EdgeInsets.fromLTRB(16, 12, 16, 12),
        child: Flex(
          direction: Axis.horizontal,
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          crossAxisAlignment: CrossAxisAlignment.center,
          children: [
            Row(
              children: [
                Container(
                  height: 18,
                  padding: const EdgeInsets.fromLTRB(0, 0, 8, 0),
                  decoration: const BoxDecoration(
                      border: Border(
                          left: BorderSide(
                            color: ColorUtil.primaryBgColor,
                            width: 4,
                          )
                      )
                  ),
                ),
                Text( title, style: const TextStyle(fontSize: 15,fontWeight: FontWeight.bold),),
              ],
            ),

            Row(
              children: [
                if(badge !=null)
                  Container(
                    padding: const EdgeInsets.fromLTRB(10, 2, 10, 2),
                    decoration: const BoxDecoration(borderRadius: BorderRadius.all(Radius.circular(8)),color: ColorUtil.primaryBadgeBgColor),
                    child: Text(badge!,style: const TextStyle(color: Colors.white,fontSize: 12),),
                  ),
                if(showMore)
                  Text(moreTitle,style: const TextStyle(color: ColorUtil.tipBgColor),),
                const Icon(Icons.arrow_right)
              ],
            )
          ],
        ),
      ),
    );
  }

  /***
   * 确认按钮
   */
  static Color newColor=ColorUtil.primaryBgColor;
  btnBox({required String title, GestureTapCallback? onTap, Color ? color}){
    return Expanded(
      flex: 1,
      child: GestureDetector(
        onTap: onTap,
        child: Container(
          padding: const EdgeInsets.fromLTRB(0, 18, 0, 18),
          color: color ?? newColor,
          child:  Center(child: Text(title,style: const TextStyle(color: Colors.white),),),
        ),
      )
    );
  }



}


CommonWidget commonWidget = CommonWidget();
